﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NCS.IConnect.ApplicationContexts;
using Microsoft.SharePoint;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using JM.JCY.Common;
using System.Data;
using JM.JCY.Common.Utilities;
using System.IO;
using System.Threading;
using System.Text;
using System.Globalization;

namespace JM.JCY.SharePointComponent.PhotoAlbum.ViewAlbum
{
    public partial class ViewAlbumUserControl : UserControl
    {
        public string appType
        {
            set;
            get;
        }
        public int appId
        {
            set;
            get;
        }
        public int _staffId
        {
            set;
            get;
        }

        public int _albumId
        {
            get;
            set;
        }

        public PhotoAlbumDataSet _albumDs
        {
            get
            {
                if (ViewState["View_albumDs"] != null)
                {
                    return (PhotoAlbumDataSet)ViewState["View_albumDs"];
                }
                else
                {
                    return new PhotoAlbumDataSet();
                }
            }
            set { ViewState["View_albumDs"] = value; }
        }

        public string _SpFolderId
        {
            get
            {
                if (ViewState["View_SpFolderId"] != null)
                {
                    return (string)ViewState["View_SpFolderId"];
                }
                else
                {
                    return "";
                }
            }
            set { ViewState["View_SpFolderId"] = value; }
        }

        public string _CreatorID
        {
            get
            {
                if (ViewState["View_CreatorID"] != null)
                {
                    return (string)ViewState["View_CreatorID"];
                }
                else
                {
                    return string.Empty;
                }
            }
            set { ViewState["View_CreatorID"] = value; }
        }

        public string _ContextAcronym
        {
            set;
            get;
        }

        static int PAGESIZE = JCYConstant.Pagination.PageSize;
        private int currentPageIndex;
        public string lastIndex = "1";
        public string _CreatedContextID
        {
            set { Session["ocp_album_createdcontextid"] = value; }
            get
            {
                if (Session["ocp_album_createdcontextid"] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return Session["ocp_album_createdcontextid"].ToString();
                }
            }
        }

        //public AccessFrameworkDataSet.StaffIDContextIDDataTable AllStaffIdWithinContextId
        //{
        //    get
        //    {
        //        if (ViewState["AllStaffId_ContextId"] == null)
        //        {
        //            return null;
        //        }
        //        else
        //        {
        //            return (AccessFrameworkDataSet.StaffIDContextIDDataTable)ViewState["AllStaffId_ContextId"];
        //        }
        //    }
        //    set
        //    {
        //        ViewState["AllStaffId_ContextId"] = value;
        //    }
        //}

        //only show confirm delete album one time,not show again even refresh page.
        public bool removeAblumOneTime
        {
            get
            {
                if (Session["735DFFE5-E595-4764-859A-83F99CE2E954"] == null)
                {
                    return false;
                }
                else
                {
                    return (bool)Session["735DFFE5-E595-4764-859A-83F99CE2E954"];
                }
            }
            set
            {
                Session["735DFFE5-E595-4764-859A-83F99CE2E954"] = value;
            }
        }

        private void LoadApplicationContext()
        {
            appId = 0;
            appType = JCYConstant.PhotoAlbum.ApplicationTypeName.PublicName;
            _staffId = 1;
        }

        

        protected void Page_Load(object sender, EventArgs e)
        {
            //try
            //{
            //    if (Request.Params["tranid"] != null && (!_CreatedContextID.Equals(string.Empty)))
            //    {
            //        using (AccessFrameworkProxy afProxy = new AccessFrameworkProxy())
            //        {
            //            AccessFrameworkDataSet.ContextDataTable condt = afProxy.GetContextNameById(Convert.ToInt32(_CreatedContextID));
            //            ApplicationContext.Current.SetKeyValue("ContextId", _CreatedContextID);
            //            if (condt.Rows.Count == 1)
            //            {
            //                ApplicationContext.Current.SetKeyValue("ContextAcronym", condt[0].contextName);
            //            }
            //            else
            //            {
            //                ApplicationContext.Current.SetKeyValue("ContextAcronym", string.Empty);
            //            }
            //        }
            //        _CreatedContextID = string.Empty;
            //        removeAblumOneTime = true;
            //        Response.Redirect(Request.Path + "?AlbumId=" + Request.Params["AlbumId"] + "&ra=DA738268-2C84-4D4F-8934-127766378FBF&ContextId=" + Request.Params["ContextId"]);
            //    }
            //    else if (Request.Params["ra"] != null && Request.Params["ra"].Equals("DA738268-2C84-4D4F-8934-127766378FBF"))
            //    {
            //        if (removeAblumOneTime)
            //        {
            //            HiddenFieldRemoveAblum.Value = "T";//true
            //        }
            //        else
            //        {
            //            HiddenFieldRemoveAblum.Value = "F";
            //        }
            //        removeAblumOneTime = false;
            //    }
            //    else
            //    {
            //        HiddenFieldRemoveAblum.Value = "F";//false;
            //    }

            //    if (ApplicationContext.Current.GetKeyValue("ContextAcronym") != null)
            //    {
            //        _ContextAcronym = ApplicationContext.Current.GetKeyValue("ContextAcronym").ToString();
            //    }

            //    if (ApplicationContext.Current.GetKeyValue("StaffId") != null)
            //    {
            //        this.HiddenStaffId.Value = ApplicationContext.Current.GetKeyValue("StaffId").ToString();
            //    }

            //    if (!Page.IsPostBack)
            //    {
            //        if (Request.QueryString["AlbumId"] != null)
            //        {
            //            _albumId = Int32.Parse(Request.QueryString["AlbumId"].ToString());
            //            this.lbViewSlideShow.PostBackUrl = "/_layouts/SharePointComponent/viewslideshow.aspx?AlbumId=" + _albumId + "&ContextId=" + this.HiddenContextId.Value;
            //            this.HiddenAlbumId.Value = _albumId.ToString();

            //            LoadAlbumContents(_albumId, 1, true);
            //            LoadPagingSetting();

            //            using (PhotoAlbumProxy accessProxy = new PhotoAlbumProxy())
            //            {
            //                _albumDs = accessProxy.getSPfolderIDbyAlbumId(Convert.ToInt32(_albumId));
            //                _SpFolderId = _albumDs.T_SharePointObject.Rows[0][_albumDs.T_SharePointObject.SPFolderIdColumn.ColumnName].ToString();
            //            }

            //            int createdContextId = _albumDs.T_Album[0].OcpContextId;
            //            _CreatedContextID = createdContextId.ToString();
            //            string albumContextType = string.Empty;
            //            string currentUserName = string.Empty;
            //            //LoginAccount
            //            if (ApplicationContext.Current.GetKeyValue("LoginAccount") != null)
            //            {
            //                currentUserName = ApplicationContext.Current.GetKeyValue("LoginAccount").ToString();
            //            }
            //            using (AccessFrameworkProxy afProxy = new AccessFrameworkProxy())
            //            {
            //                AccessFrameworkDataSet.T_OcpContextDataTable condt = afProxy.GetContextById(createdContextId);
            //                if (condt.Rows.Count == 1)
            //                {
            //                    albumContextType = condt[0].ContextType;
            //                }

            //                string contextTypeName = string.Empty;
            //                AccessFrameworkDataSet.ContextDataTable cdt = afProxy.GetContextNameById(createdContextId);
            //                if (cdt.Rows.Count == 1)
            //                {
            //                    contextTypeName = cdt[0].contextName;
            //                }

            //                if (albumContextType.Equals("Staff"))
            //                {
            //                    //current web is in mysite.
            //                    if (_staffId.Equals(_albumDs.T_Album[0].Creator))
            //                    {
            //                        HiddenFieldBelongedGroup.Value = "MySite";
            //                        HiddenFieldCurrentGroup.Value = "MySite";
            //                        HiddenFieldEableEdit.Value = "T";//true.
            //                        HiddenFieldAlbumUrl.Value = "/MySite/MOHPages/";
            //                    }
            //                    else
            //                    {
            //                        HiddenFieldBelongedGroup.Value = "MySite";
            //                        HiddenFieldCurrentGroup.Value = "MySite";
            //                        HiddenFieldEableEdit.Value = "F";//False.
            //                        HiddenFieldAlbumUrl.Value = "";
            //                    }
            //                }
            //                else if (albumContextType.Equals("Workgroup"))
            //                {
            //                    //the album is in workgroup
            //                    AccessFrameworkDataSet.WorkgroupContextDataTable StaffGroupDT = afProxy.GetAllWorkgroupContexts(ApplicationContext.Current.GetKeyValue("LoginAccount").ToString());
            //                    DataRow[] rows = StaffGroupDT.Select(string.Format("OrgUnitAcronym='{0}'", contextTypeName));

            //                    if (rows.Length > 0)
            //                    {
            //                        HiddenFieldEableEdit.Value = "T";
            //                        HiddenFieldBelongedGroup.Value = contextTypeName;
            //                        HiddenFieldCurrentGroup.Value = _ContextAcronym;
            //                        HiddenFieldAlbumUrl.Value = "/MyWorkGroup/MOHPages/funatwork";
            //                    }
            //                    else
            //                    {
            //                        HiddenFieldEableEdit.Value = "F";
            //                        HiddenFieldBelongedGroup.Value = "";
            //                        HiddenFieldCurrentGroup.Value = _ContextAcronym;
            //                        HiddenFieldAlbumUrl.Value = "";
            //                    }

            //                }
            //                else if (albumContextType.Equals("Committee"))
            //                {
            //                    //the album is in committe
            //                    AccessFrameworkDataSet.StaffIDContextIDDataTable allStaffid = afProxy.GetAllStaffIDbyContextId(createdContextId, "Committee");
            //                    DataRow[] rows = allStaffid.Select(string.Format("StaffID={0} and Acronym='{1}'", _staffId, contextTypeName));

            //                    if (rows.Length > 0)
            //                    {
            //                        HiddenFieldEableEdit.Value = "T";
            //                        HiddenFieldBelongedGroup.Value = contextTypeName;
            //                        HiddenFieldCurrentGroup.Value = _ContextAcronym;
            //                        HiddenFieldAlbumUrl.Value = "/MyCommittee/MOHPages/funatwork";
            //                    }
            //                    else
            //                    {
            //                        HiddenFieldEableEdit.Value = "F";
            //                        HiddenFieldBelongedGroup.Value = "";
            //                        HiddenFieldCurrentGroup.Value = _ContextAcronym;
            //                        HiddenFieldAlbumUrl.Value = "";
            //                    }

            //                    AllStaffIdWithinContextId = allStaffid;
            //                }
            //            }
            //        }
            //    }
            //    string removeablum = Request.Params.Get("__EVENTTARGET");
            //    if (removeablum != null && removeablum.IndexOf("removeAlbum") > -1)
            //    {
            //        lbRemoveThisAlbum_Click(sender, e);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    bool isok = OCPUtility.ExceptionHandle("view album loading", ex);
            //    if (isok == false)
            //    {
            //        throw ex;
            //    }
            //}
        }

        private void LoadPagingSetting()
        {
            Session["AlbumContentDT"] = null;
            string callbackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveCallback", "context", false);
            string callbackScript = string.Format("function CallServer(arg,context){{ {0}  }}", callbackReference);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
        }

        private void LoadAlbumContents(int albumId, int pageIndex, bool needRender)
        {
            //try
            //{
            //    int contextId = 0;
            //    if (_CreatorID.Equals(string.Empty))
            //    {
            //        using (FunworkHeartworkProxy accessProxy = new FunworkHeartworkProxy())
            //        {
            //            FunworkHeartworkDataSet funds = accessProxy.getSPfolderIDbyAlbumId(albumId);
            //            if (funds.T_Album.Rows.Count == 0)
            //            {
            //                _CreatorID = "0";
            //            }
            //            else
            //            {
            //                _CreatorID = funds.T_Album[0].Creator.ToString();
            //            }
            //        }
            //    }
            //    AlbumDataSet.T_AlbumContentDataTable contentDT = new AlbumDataSet.T_AlbumContentDataTable();
            //    if (ViewState["AlbumContentDT"] == null)
            //    {
            //        using (FunworkHeartworkProxy proxy = new FunworkHeartworkProxy())
            //        {
            //            contentDT = proxy.GetAlbumContents(albumId);
            //            //this.DatalistViewAlbum.DataSource = contentDT;
            //            //this.DatalistViewAlbum.DataBind();
            //        }
            //        ViewState["AlbumContentDT"] = contentDT;

            //    }
            //    else
            //    {
            //        contentDT = (AlbumDataSet.T_AlbumContentDataTable)ViewState["AlbumContentDT"];
            //    }
            //    // load owner info
            //    if (contentDT.Rows.Count > 0)
            //    {
            //        this.HiddenSharingOption.Value = contentDT.Rows[0][contentDT.SharingOptionColumn.ColumnName].ToString();
            //        this.HiddenLastUpdatedTime.Value = contentDT[0].AlbumUpdatedTime.ToString("yyyy-MM-dd HH:mm:ss");
            //        this.HiddenObjectId.Value = contentDT[0].AlbumObjectId.ToString();
            //        string weburl = string.Empty;
            //        if (contentDT[0].OriginalImgUrl.ToLower().IndexOf("mysite") > -1)
            //        {
            //            weburl = "MySite";
            //        }
            //        else if (contentDT[0].OriginalImgUrl.ToLower().IndexOf("myworkgroup") > -1)
            //        {
            //            weburl = "MyWorkGroup";
            //        }
            //        else if (contentDT[0].OriginalImgUrl.ToLower().IndexOf("mycommittee") > -1)
            //        {
            //            weburl = "MyCommittee";
            //        }
            //        string creator = contentDT[0].CREATED_BY;
            //        creator = creator.Substring(0, creator.Length > 30 ? 30 : creator.Length);
            //        this.lblCreater.Text = "By <a href='/" + weburl + "/MOHPages/staffprofile/StaffProfileDetails.aspx?staffid=" + _CreatorID + "&ContextId=" + HiddenContextId.Value + "'>" + creator + "</a>";
            //        string albumName = contentDT[0].AlbumName;
            //        albumName = albumName.Substring(0, albumName.Length > 30 ? 30 : albumName.Length);
            //        this.lblAlbumName.Text = albumName;
            //        // substring tool tip if need
            //        this.lblAlbumName.ToolTip = contentDT[0].AlbumName;
            //        this.lblAlbumDesc.Text = contentDT[0].AlbumDescription;
            //        contextId = contentDT[0].OcpContextId;
            //        HiddenFieldTargetContextId.Value = contentDT[0].OcpContextId.ToString();
            //        new CommonFunctions().SetContextAndIcon(lblContextAcronym, imgContextIcon, contextId);
            //    }

            //    //Calculate total page count
            //    int pages = (contentDT.Rows.Count % PAGESIZE == 0) ? contentDT.Rows.Count / PAGESIZE : (contentDT.Rows.Count / PAGESIZE) + 1;
            //    lastIndex = pages.ToString();
            //    HiddenFieldPageNum.Value = pages.ToString();
            //    if (pageIndex > pages)
            //        pageIndex = pages;
            //    else if (pageIndex < 1)
            //        pageIndex = 1;
            //    int startId = (pageIndex - 1) * PAGESIZE + 1;
            //    int endId = pageIndex * PAGESIZE;

            //    DatalistViewAlbum.DataSource = GetNewDataTable(contentDT, string.Format("id>={0} and id<={1}", startId, endId)); ;
            //    DatalistViewAlbum.DataBind();
            //}
            //catch (Exception ex)
            //{
            //    bool isok = OCPUtility.ExceptionHandle("LoadAlbumContents in view album", ex);
            //    if (isok == false)
            //    {
            //        throw ex;
            //    }
            //}

        }

        private DataTable GetNewDataTable(DataTable dt, string condition)
        {
            DataTable newDT = new DataTable();
            newDT = dt.Clone();
            DataRow[] dr = dt.Select(condition);
            for (int i = 0; i <= dr.Length - 1; i++)
            {
                newDT.ImportRow((DataRow)dr[i]);
            }
            return newDT;
        }

        public string GetCallbackResult()
        {
            //Return the rebind datalist's content
            return RenderControl(DatalistViewAlbum);
        }

        //Realize ICallbackEventHandler member RaiseCallbackEvent
        public void RaiseCallbackEvent(string eventArgument)
        {
            //int albumId = Int32.Parse(Request.QueryString["AlbumId"].ToString());
            currentPageIndex = Convert.ToInt32(eventArgument);
            LoadAlbumContents(int.Parse(this.HiddenAlbumId.Value), currentPageIndex, false);
        }

        private string RenderControl(Control control)
        {
            StringWriter writer1 = new StringWriter(CultureInfo.InvariantCulture);
            HtmlTextWriter writer2 = new HtmlTextWriter(writer1);

            control.RenderControl(writer2);
            writer2.Flush();
            writer2.Close();

            return writer1.ToString();
        }

        protected void DatalistViewAlbum_OnItemDataBound(object sender, DataListItemEventArgs e)
        {
            //DataRowView drv = (DataRowView)e.Item.DataItem;
            //int MediaId = Int32.Parse(this.DatalistViewAlbum.DataKeys[e.Item.ItemIndex].ToString());
            //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            //{
            //    Literal viewLink = (Literal)e.Item.FindControl("LiteralViewMedia");
            //    viewLink.Text = "<a href='ViewMedia.aspx?MediaId=" + MediaId + "&AlbumId=" + int.Parse(this.HiddenAlbumId.Value) + "&ContextId=" + this.HiddenContextId.Value + "'> <img src='" + drv["ThumbNailImgUrl"].ToString() + "' alt='" + drv["Description"].ToString() + "' width='159px' height='126px'></a>";
            //    Label lblLike = (Label)e.Item.FindControl("lblLikeCount");
            //    LinkButton lkbtLike = (LinkButton)e.Item.FindControl("lkbLike");

            //    string objectType = string.Empty;
            //    switch (drv["MediaType"].ToString())
            //    {
            //        case OCPConstant.MediaType.AudioType:
            //            objectType = OCPConstant.NewsfeedParams.LikeObjectType.FunWorkAudio;
            //            break;
            //        case OCPConstant.MediaType.VedioType:
            //            objectType = OCPConstant.NewsfeedParams.LikeObjectType.FunWorkVideo;
            //            break;
            //        case OCPConstant.MediaType.PictureType:
            //            objectType = OCPConstant.NewsfeedParams.LikeObjectType.FunWorkPicture;
            //            break;
            //        default:
            //            objectType = string.Empty;
            //            break;
            //    }

            //    int[] likeResult = GetLikes(MediaId, objectType);
            //    lblLike.Text = likeResult[0].ToString();
            //    if (likeResult[1] == 0)
            //    {
            //        lkbtLike.Text = "Like";
            //    }
            //    else
            //    {
            //        lkbtLike.Text = "Unlike";
            //    }

            //    lkbtLike.Attributes.Add("onclick", "clickLike('" + MediaId + "','" + lkbtLike.ClientID + "','" + lblLike.ClientID + "','" + objectType + "');return false;");
            //}
        }

        protected void lbRemoveThisAlbum_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    SPInputs deleteInput = new SPInputs();
            //    deleteInput.SiteName = SPContext.Current.Web.Title;
            //    deleteInput.SPFolderID = _SpFolderId;
            //    SPOutputs deleteOut = OCPSharePointHelper.RemoveAlbum(deleteInput);
            //    if (deleteOut.IsError == false)
            //    {
            //        IList<int> reciptid = new List<int>();
            //        int createdContextId = Convert.ToInt32(Request.QueryString["AlbumId"].ToString());
            //        string contextTypeName = string.Empty;
            //        using (AccessFrameworkProxy accessProxy = new AccessFrameworkProxy())
            //        {
            //            AccessFrameworkDataSet.ContextDataTable cdt = accessProxy.GetContextNameById(createdContextId);
            //            if (cdt.Rows.Count == 1)
            //            {
            //                contextTypeName = cdt[0].contextType;
            //            }
            //            AccessFrameworkDataSet.StaffIDContextIDDataTable staffIdByContextId = accessProxy.GetAllStaffIDbyContextId(createdContextId, contextTypeName);
            //            foreach (AccessFrameworkDataSet.StaffIDContextIDRow row in staffIdByContextId)
            //            {
            //                if (row.StaffID != _staffId && reciptid.Contains(row.StaffID) == false)
            //                {
            //                    reciptid.Add(row.StaffID);
            //                }
            //            }
            //        }

            //        foreach (FunworkHeartworkDataSet.T_SharePointObjectRow objRow in _albumDs.T_SharePointObject.Rows)
            //        {
            //            objRow.IsDeleted = true;
            //            objRow.LAST_UPDATED_BY = SPContext.Current.Web.CurrentUser.Name;
            //            objRow.LAST_UPDATED_TIME = DateTime.Now;
            //        }

            //        foreach (FunworkHeartworkDataSet.T_AlbumRow albumRow in _albumDs.T_Album.Rows)
            //        {
            //            albumRow.IsDeleted = true;
            //            albumRow.LatestUpdateTime = DateTime.Now;
            //            albumRow.LAST_UPDATED_TIME = DateTime.Now;
            //            albumRow.LAST_UPDATED_BY = SPContext.Current.Web.CurrentUser.Name;
            //        }

            //        foreach (FunworkHeartworkDataSet.T_AlbumContentRow contentRow in _albumDs.T_AlbumContent.Rows)
            //        {
            //            contentRow.IsDeleted = true;
            //            contentRow.LAST_UPDATED_BY = SPContext.Current.Web.CurrentUser.Name;
            //            contentRow.LAST_UPDATED_TIME = DateTime.Now;
            //        }
            //        using (FunworkHeartworkProxy funProxy = new FunworkHeartworkProxy())
            //        {
            //            funProxy.UpdateAlbum(_albumDs);
            //        }

            //        if (SPContext.Current.Web.Title.ToLower().Equals("mysite") == false && reciptid.Count > 0)
            //        {
            //            using (StaffProfileProxy staffproxy = new StaffProfileProxy())
            //            {
            //                StaffProfileDataSet.StaffProfileByIDDataTable staffProfile = staffproxy.GetStaffProfileByID(_staffId);
            //                MultipleNotifications multifications = new MultipleNotifications();
            //                multifications.ApplicationId = _albumDs.T_SharePointObject[0].ApplicationId;
            //                multifications.SenderId = _staffId;
            //                multifications.ActualContent = string.Format("<a href=\"{0}/MOHPages/staffprofile/StaffProfileDetails.aspx?staffid={1}\">{2}</a> has removed the album {3}", SPContext.Current.Web.ServerRelativeUrl, _staffId, staffProfile[0].StaffName, _albumDs.T_Album[0].Name);
            //                multifications.DisplayContent = staffProfile.Rows[0]["StaffName"].ToString() + " has removed the album " + _albumDs.T_Album[0].Name;
            //                multifications.RedirectUrl = SPContext.Current.Web.ServerRelativeUrl + "/MOHPages/funatwork/AlbumCategories.aspx?ContextId=" + this.HiddenContextId.Value;
            //                multifications.IsRead = true;
            //                multifications.CreatedBy = _staffId;

            //                multifications.RecipientId = reciptid;
            //                using (NotificationProxy noticProxy = new NotificationProxy())
            //                {
            //                    noticProxy.InsertNotifications(multifications);
            //                }
            //            }
            //        }

            //        //delete feedpost
            //        using (NewsfeedProxy feedPoxy = new NewsfeedProxy())
            //        {
            //            NewsfeedDataSet.T_FeedPostDataTable newsFeedpstdt = feedPoxy.GetFeedPostBySpObjId(_albumDs.T_Album[0].SharePointObjectId);
            //            if (newsFeedpstdt.Rows.Count == 1)
            //            {
            //                NewsfeedDataSet.T_FeedPostRow postRow = newsFeedpstdt[0];
            //                postRow.StaffId = _staffId;
            //                postRow.IsDeleted = true;
            //                postRow.LatestUpdateTime = DateTime.Now;
            //                postRow.StaffName = ApplicationContext.Current.UserName.ToString();

            //                postRow.LAST_UPDATED_BY = ApplicationContext.Current.UserName.ToString();
            //                postRow.LAST_UPDATED_TIME = DateTime.Now;
            //                feedPoxy.UpdateFeedPostTable(newsFeedpstdt);
            //            }

            //            foreach (FunworkHeartworkDataSet.T_AlbumContentRow contRow in _albumDs.T_AlbumContent)
            //            {
            //                NewsfeedDataSet.T_FeedPostDataTable contnewsfeed = feedPoxy.GetFeedPostBySpObjId(contRow.SharePointObjectId);
            //                if (contnewsfeed.Rows.Count == 1)
            //                {
            //                    NewsfeedDataSet.T_FeedPostRow postRow = contnewsfeed[0];
            //                    postRow.StaffId = _staffId;
            //                    postRow.IsDeleted = true;
            //                    postRow.LatestUpdateTime = DateTime.Now;
            //                    postRow.StaffName = ApplicationContext.Current.UserName.ToString();

            //                    postRow.LAST_UPDATED_BY = ApplicationContext.Current.UserName.ToString();
            //                    postRow.LAST_UPDATED_TIME = DateTime.Now;
            //                    feedPoxy.UpdateFeedPostTable(contnewsfeed);
            //                }
            //            }
            //        }
            //    }
            //    else
            //    {
            //        showMessage(deleteOut.Message.Replace("\r\n", ""));
            //        return;
            //    }

            //    Response.Redirect("AlbumCategories.aspx?ContextId=" + this.HiddenContextId.Value);
            //}
            //catch (Exception ex)
            //{
            //    bool isok = OCPUtility.ExceptionHandle("delete album", ex);
            //    if (isok == false)
            //    {
            //        throw ex;
            //    }
            //}
        }

        public void showMessage(string msg)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Error Message", "alert(\"" + msg + "\");", true);
        }

        //private AccessFrameworkDataSet.T_OcpApplicationDataTable GetApplicationByName(string appName)
        //{
        //    using (AccessFrameworkProxy proxy = new AccessFrameworkProxy())
        //    {
        //        AccessFrameworkDataSet.T_OcpApplicationDataTable appDT = proxy.GetApplicationByName(appName);
        //        if (appDT.Rows.Count > 0)
        //            return appDT;
        //        else
        //            return null;
        //    }
        //}

        private int[] GetLikes(int spobjectid, string objectType)
        {
            int[] result = new int[2];
            //using (NewsfeedProxy nfProxy = new NewsfeedProxy())
            //{
            //    NewsfeedDataSet.T_LikeDataTable ldt = nfProxy.GetLikes(spobjectid, objectType);
            //    if (ldt.Count > 0)
            //    {
            //        result[0] = ldt.Count;
            //        DataRow[] lkes = ldt.Select(string.Format("StaffId={0}", _staffId));
            //        if (lkes.Length == 1)
            //        {
            //            result[1] = 1;//1:to show unlike.
            //        }
            //        else
            //        {
            //            result[1] = 0;//0:to show like.
            //        }
            //    }
            //    else
            //    {
            //        result[0] = 0;
            //        result[1] = 0;//0:to show like.
            //    }
            //}

            return result;
        }
    }
}
